{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import uuid\n",
    "from docx import Document\n",
    "from docx.enum.style import WD_BUILTIN_STYLE\n",
    "from docx.enum.text import WD_ALIGN_PARAGRAPH\n",
    "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT\n",
    "from win32com import client as wc\n",
    "from docx.shared import Inches\n",
    "from docx.shared import Pt\n",
    "from docx.oxml.ns import qn\n",
    "from docx.shared import RGBColor\n",
    "\n",
    "\n",
    "'''========================================================================='''\n",
    "# path1 = './测试数据/awa.docx'\n",
    "# docx = Document(path1)\n",
    "# print(f'行距:{docx.paragraphs[52].style.paragraph_format.line_spacing}')  #行距\n",
    "# print(f'段落前间距:{docx.paragraphs[52].style.paragraph_format.space_before}')  # 段落前间距    有问题\n",
    "# print(f'段落后间距:{docx.paragraphs[52].style.paragraph_format.space_after}')  # 段落后间距      有问题\n",
    "# print(f'段落对齐方式:{docx.paragraphs[52].style.paragraph_format.alignment}')  # 段落对齐方式\n",
    "# print(f'左缩进:{docx.paragraphs[52].style.paragraph_format.left_indent}')  # 左缩进     有问题\n",
    "# print(f'右缩进:{docx.paragraphs[52].style.paragraph_format.right_indent}')  # 右缩进    有问题\n",
    "# print(f'行间距:{docx.paragraphs[52].style.paragraph_format.line_spacing}')  # 行间距    有问题\n",
    "# print(f'设置字体颜色:{docx.paragraphs[52].style.font.color.rgb}')  # 设置字体颜色\n",
    "# print(f'设置字体名称:{docx.paragraphs[52].style.font.name}')  # 设置字体名称\n",
    "# print(f'设置字体大小:{docx.paragraphs[52].style.font.size}')  # 设置字体大小      有问题\n",
    "'''========================================================================='''\n",
    "\n",
    "\n",
    "\n",
    "'''========================================================================='''\n",
    "path2 = './测试数据/qwq.docx'\n",
    "docx1 =Document()\n",
    "# 添加一个段落\n",
    "paragraph = docx1.add_paragraph()\n",
    "# 获得一个段落句柄\n",
    "paragraph_format = paragraph.paragraph_format\n",
    "# 段落前间距\n",
    "paragraph.space_before = Pt(20)\n",
    "# 段落后间距\n",
    "paragraph.space_after = Pt(20)\n",
    "# 段落对齐方式\n",
    "paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER\n",
    "# 左缩进\n",
    "paragraph.left_indent = Inches(2.0)\n",
    "# 右缩进\n",
    "paragraph.right_indent = Pt(2.0)\n",
    "# 行间距\n",
    "paragraph.line_spacing = Pt(2.0)\n",
    "# 添加段落文字以及句柄\n",
    "font_obj = paragraph.add_run('我是有法可依空格和客观将会给客户共和国空军公开改空行给客户给开个开个看见更何况给中国人')\n",
    "# 设置字体名称\n",
    "font_obj.font.name = u'黑体'\n",
    "r = font_obj._element\n",
    "r.rPr.rFonts.set(qn('w:eastAsia'), '黑体')\n",
    "# 设置字体颜色\n",
    "font_obj.font.color.rgb = RGBColor(0x42, 0x24, 0xE9)\n",
    "# 设置字体大小\n",
    "font_obj.font.size = Pt(20)\n",
    "# 保存\n",
    "docx1.save(path2)\n",
    "'''========================================================================='''\n",
    "\n",
    "# path3 = './测试数据/qwq.docx'\n",
    "# docx3 = Document(path3)\n",
    "# print(f'行距:{docx3.paragraphs[0].style.paragraph_format.line_spacing}')  #行距\n",
    "# print(f'段落前间距:{docx3.paragraphs[0].style.paragraph_format.space_before}')  # 段落前间距\n",
    "# print(f'段落后间距:{docx3.paragraphs[0].style.paragraph_format.space_after}')  # 段落后间距\n",
    "# print(f'段落对齐方式:{docx3.paragraphs[0].style.paragraph_format.alignment}')  # 段落对齐方式\n",
    "# print(f'左缩进:{docx3.paragraphs[0].style.paragraph_format.left_indent}')  # 左缩进\n",
    "# print(f'右缩进:{docx3.paragraphs[0].style.paragraph_format.right_indent}')  # 右缩进\n",
    "# print(f'行间距:{docx3.paragraphs[0].style.paragraph_format.line_spacing}')  # 行间距\n",
    "# print(f'设置字体颜色:{docx3.paragraphs[0].style.font.color.rgb}')  # 设置字体颜色\n",
    "# print(f'设置字体名称:{docx3.paragraphs[0].style.font.name}')  # 设置字体名称\n",
    "# print(f'设置字体大小:{docx3.paragraphs[0].style.font.size}')  # 设置字体大小"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
